import 'package:flutter/material.dart';
import 'package:x3_base_core/base_models/base_key_value_model.dart';
import 'package:x3_form_core/filter_components/mixin/advanced_filter_select_mixin.dart';
import 'package:x3_form_core/models/base_advanced_filter_model.dart';

/// author：william on 2021/4/12 14:44
/// email：362661044@qq.com

class AdvancedFilterSingleChoice extends StatefulWidget {
  final BaseAdvancedFilterModel model;

  const AdvancedFilterSingleChoice({Key key, this.model}) : super(key: key);

  @override
  _AdvancedFilterSingleChoiceState createState() => _AdvancedFilterSingleChoiceState();
}

class _AdvancedFilterSingleChoiceState extends State<AdvancedFilterSingleChoice> with AdvancedFilterSelectMixin {
  @override
  Widget build(BuildContext context) {
    return buildItemContainer();
  }

  @override
  List<BaseKeyValueModel> get children => widget.model.selectData ?? [];

  @override
  BaseAdvancedFilterModel get model => widget.model;

  @override
  onChange(bool v, BaseKeyValueModel data) {
    onSingleChangeEvent(v, data);
    baseRequestFormProvider.setDataSource(this.model, selectedList.length == 1 ? selectedList.first.toJson() : {});
    setState(() {});
  }
}
